home *** CD-ROM | disk | FTP | other *** search
/ The Complete Utilities To…ka 501 Killer Utilities! / 501 Killer Utilities! (Macworld July 1995).cdr / Programming / OutOfPhase1.1 Source / OutOfPhase Folder / DisassemblyWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-28  |  11.1 KB  |  352 lines  |  [TEXT/KAHL]

  1. /* DisassemblyWindow.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "DisassemblyWindow.h"
  31. #include "Screen.h"
  32. #include "TextEdit.h"
  33. #include "Memory.h"
  34. #include "MainWindowStuff.h"
  35. #include "GrowIcon.h"
  36. #include "Main.h"
  37. #include "WindowDispatcher.h"
  38. #include "GlobalWindowMenuList.h"
  39. #include "FindDialog.h"
  40.  
  41.  
  42. struct DisaWindowRec
  43.     {
  44.         MainWindowRec*            Owner;
  45.         WinType*                        ScreenID;
  46.         TextEditRec*                Editor;
  47.         GenericWindowRec*        MyGenericWindow; /* how the window event dispatcher knows us */
  48.         MenuItemType*                MyMenuItem;
  49.     };
  50.  
  51.  
  52. /* create a new disassembly window.  the window is basically a non-editable text */
  53. /* field containing the Data passed in (linefeed = 0x0a).  the caller is responsible */
  54. /* for disposing of Data.  the function automatically notifies the main window */
  55. /* that it has been created. */
  56. DisaWindowRec*            NewDisassemblyWindow(char* Data, MainWindowRec* Owner)
  57.     {
  58.         DisaWindowRec*        Window;
  59.  
  60.         Window = (DisaWindowRec*)AllocPtrCanFail(sizeof(DisaWindowRec),"DisaWindowRec");
  61.         if (Window == NIL)
  62.             {
  63.              FailurePoint1:
  64.                 return NIL;
  65.             }
  66.         Window->Owner = Owner;
  67.         Window->ScreenID = MakeNewWindow(eDocumentWindow,eWindowClosable,
  68.             eWindowZoomable,eWindowResizable,GetScreenWidth()
  69.             - (2 + WindowOtherEdgeWidths(eDocumentWindow)) - 400,
  70.             2 + WindowTitleBarHeight(eDocumentWindow),400,GetScreenHeight()
  71.             - WindowTitleBarHeight(eDocumentWindow)
  72.             - WindowOtherEdgeWidths(eDocumentWindow) - 4,
  73.             (void (*)(void*))&DisassemblyWindowUpdator,Window);
  74.         if (Window->ScreenID == 0)
  75.             {
  76.              FailurePoint2:
  77.                 ReleasePtr((char*)Window);
  78.                 goto FailurePoint1;
  79.             }
  80.         SetWindowName(Window->ScreenID,"Disassembly");
  81.         Window->Editor = NewTextEdit(Window->ScreenID,
  82.             (TEScrollType)(eTEVScrollBar | eTEHScrollBar),GetMonospacedFont(),9,-1,-1,
  83.             GetWindowWidth(Window->ScreenID) + 2,GetWindowHeight(Window->ScreenID) + 2);
  84.         if (Window->Editor == NIL)
  85.             {
  86.              FailurePoint3:
  87.                 KillWindow(Window->ScreenID);
  88.                 goto FailurePoint2;
  89.             }
  90.         if (!MainWindowNewDisassemblyNotify(Owner,Window))
  91.             {
  92.              FailurePoint4:
  93.                 DisposeTextEdit(Window->Editor);
  94.                 goto FailurePoint3;
  95.             }
  96.         Window->MyGenericWindow = CheckInNewWindow(Window->ScreenID,Window,
  97.             (void (*)(void*,MyBoolean,OrdType,OrdType,ModifierFlags))&DisassemblyWindowDoIdle,
  98.             (void (*)(void*))&DisassemblyWindowBecomeActive,
  99.             (void (*)(void*))&DisassemblyWindowBecomeInactive,
  100.             (void (*)(void*))&DisassemblyWindowJustResized,
  101.             (void (*)(OrdType,OrdType,ModifierFlags,void*))&DisassemblyWindowDoMouseDown,
  102.             (void (*)(unsigned char,ModifierFlags,void*))&DisassemblyWindowDoKeyDown,
  103.             (void (*)(void*))&DisassemblyWindowClose,
  104.             (void (*)(void*))&DisassemblyWindowMenuSetup,
  105.             (void (*)(void*,MenuItemType*))&DisassemblyWindowDoMenuCommand);
  106.         if (Window->MyGenericWindow == NIL)
  107.             {
  108.              FailurePoint5:
  109.                 MainWindowDisassemblyClosingNotify(Owner,Window);
  110.                 goto FailurePoint4;
  111.             }
  112.         Window->MyMenuItem = MakeNewMenuItem(mmWindowMenu,"Disassembly",0);
  113.         if (Window->MyMenuItem == NIL)
  114.             {
  115.              FailurePoint6:
  116.                 CheckOutDyingWindow(Window->MyGenericWindow);
  117.                 goto FailurePoint5;
  118.             }
  119.         if (!RegisterWindowMenuItem(Window->MyMenuItem,(void (*)(void*))&ActivateThisWindow,
  120.             Window->ScreenID))
  121.             {
  122.              FailurePoint7:
  123.                 KillMenuItem(Window->MyMenuItem);
  124.                 goto FailurePoint6;
  125.             }
  126.         TextEditNewRawData(Window->Editor,Data,"\x0a");
  127.         return Window;
  128.     }
  129.  
  130.  
  131. /* dispose of the disassembly window.  this automatically notifies the main window */
  132. /* that it has been destroyed. */
  133. void                                DisposeDisassemblyWindow(DisaWindowRec* Window)
  134.     {
  135.         CheckPtrExistence(Window);
  136.         DeregisterWindowMenuItem(Window->MyMenuItem);
  137.         KillMenuItem(Window->MyMenuItem);
  138.         CheckOutDyingWindow(Window->MyGenericWindow);
  139.         DisposeTextEdit(Window->Editor);
  140.         KillWindow(Window->ScreenID);
  141.         ReleasePtr((char*)Window);
  142.     }
  143.  
  144.  
  145. void                                DisassemblyWindowDoIdle(DisaWindowRec* Window,
  146.                                             MyBoolean CheckCursorFlag, OrdType XLoc, OrdType YLoc,
  147.                                             ModifierFlags Modifiers)
  148.     {
  149.         CheckPtrExistence(Window);
  150.         TextEditUpdateCursor(Window->Editor);
  151.         if (CheckCursorFlag)
  152.             {
  153.                 if (TextEditIBeamTest(Window->Editor,XLoc,YLoc))
  154.                     {
  155.                         SetIBeamCursor();
  156.                     }
  157.                  else
  158.                     {
  159.                         SetArrowCursor();
  160.                     }
  161.             }
  162.     }
  163.  
  164.  
  165. void                                DisassemblyWindowBecomeActive(DisaWindowRec* Window)
  166.     {
  167.         OrdType                        XSize;
  168.         OrdType                        YSize;
  169.  
  170.         CheckPtrExistence(Window);
  171.         EnableTextEditSelection(Window->Editor);
  172.         XSize = GetWindowWidth(Window->ScreenID);
  173.         YSize = GetWindowHeight(Window->ScreenID);
  174.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  175.         DrawBitmap(Window->ScreenID,XSize-15,YSize-15,GetGrowIcon(True/*enablegrowicon*/));
  176.     }
  177.  
  178.  
  179. void                                DisassemblyWindowBecomeInactive(DisaWindowRec* Window)
  180.     {
  181.         OrdType                        XSize;
  182.         OrdType                        YSize;
  183.  
  184.         CheckPtrExistence(Window);
  185.         DisableTextEditSelection(Window->Editor);
  186.         XSize = GetWindowWidth(Window->ScreenID);
  187.         YSize = GetWindowHeight(Window->ScreenID);
  188.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  189.         DrawBitmap(Window->ScreenID,XSize-15,YSize-15,GetGrowIcon(False/*disablegrowicon*/));
  190.     }
  191.  
  192.  
  193. void                                DisassemblyWindowJustResized(DisaWindowRec* Window)
  194.     {
  195.         CheckPtrExistence(Window);
  196.         SetTextEditPosition(Window->Editor,-1,-1,GetWindowWidth(Window->ScreenID) + 2,
  197.             GetWindowHeight(Window->ScreenID) + 2);
  198.     }
  199.  
  200.  
  201. void                                DisassemblyWindowDoMouseDown(OrdType XLoc, OrdType YLoc,
  202.                                             ModifierFlags Modifiers, DisaWindowRec* Window)
  203.     {
  204.         CheckPtrExistence(Window);
  205.         if ((XLoc >= GetWindowWidth(Window->ScreenID) - 15)
  206.             && (XLoc < GetWindowWidth(Window->ScreenID))
  207.             && (YLoc >= GetWindowHeight(Window->ScreenID) - 15)
  208.             && (YLoc < GetWindowHeight(Window->ScreenID)))
  209.             {
  210.                 UserGrowWindow(Window->ScreenID,XLoc,YLoc);
  211.                 DisassemblyWindowJustResized(Window);
  212.             }
  213.         else if (TextEditHitTest(Window->Editor,XLoc,YLoc))
  214.             {
  215.                 TextEditDoMouseDown(Window->Editor,XLoc,YLoc,Modifiers);
  216.             }
  217.     }
  218.  
  219.  
  220. void                                DisassemblyWindowDoKeyDown(unsigned char KeyCode,
  221.                                             ModifierFlags Modifiers, DisaWindowRec* Window)
  222.     {
  223.         CheckPtrExistence(Window);
  224.         if ((KeyCode == eLeftArrow) || (KeyCode == eRightArrow)
  225.             || (KeyCode == eUpArrow) || (KeyCode == eDownArrow))
  226.             {
  227.                 TextEditDoKeyPressed(Window->Editor,KeyCode,Modifiers);
  228.             }
  229.     }
  230.  
  231.  
  232. void                                DisassemblyWindowClose(DisaWindowRec* Window)
  233.     {
  234.         CheckPtrExistence(Window);
  235.         /* notification of closing is here and not in dispose because FunctionWindow */
  236.         /* calls dispose, so it knows that we are dying, but this routine handles */
  237.         /* a user close, which FunctionWindow doesn't know about */
  238.         MainWindowDisassemblyClosingNotify(Window->Owner,Window);
  239.         DisposeDisassemblyWindow(Window);
  240.     }
  241.  
  242.  
  243. void                                DisassemblyWindowUpdator(DisaWindowRec* Window)
  244.     {
  245.         OrdType                        XSize;
  246.         OrdType                        YSize;
  247.  
  248.         CheckPtrExistence((char*)Window);
  249.         TextEditFullRedraw(Window->Editor);
  250.         XSize = GetWindowWidth(Window->ScreenID);
  251.         YSize = GetWindowHeight(Window->ScreenID);
  252.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  253.         DrawBitmap(Window->ScreenID,XSize-15,YSize-15,
  254.             GetGrowIcon(Window->MyGenericWindow == GetCurrentWindowID()));
  255.     }
  256.  
  257.  
  258. void                                DisassemblyWindowMenuSetup(DisaWindowRec* Window)
  259.     {
  260.         CheckPtrExistence(Window);
  261.         MainWindowEnableGlobalMenus(Window->Owner);
  262.         ChangeItemName(mCloseFile,"Close Disassembly Viewer");
  263.         EnableMenuItem(mCloseFile);
  264.         if (TextEditIsThereValidSelection(Window->Editor))
  265.             {
  266.                 EnableMenuItem(mCopy);
  267.                 ChangeItemName(mCopy,"Copy Text");
  268.             }
  269.         EnableMenuItem(mSelectAll);
  270.         ChangeItemName(mSelectAll,"Select All Text");
  271.         EnableMenuItem(mFind);
  272.         if (PtrSize(GlobalSearchString) != 0)
  273.             {
  274.                 EnableMenuItem(mFindAgain);
  275.             }
  276.         EnableMenuItem(mShowSelection);
  277.         if (TextEditIsThereValidSelection(Window->Editor))
  278.             {
  279.                 EnableMenuItem(mEnterSelection);
  280.             }
  281.         SetItemCheckmark(Window->MyMenuItem);
  282.     }
  283.  
  284.  
  285. void                                DisassemblyWindowDoMenuCommand(DisaWindowRec* Window,
  286.                                             MenuItemType* MenuItem)
  287.     {
  288.         if (MainWindowDoGlobalMenuItem(Window->Owner,MenuItem))
  289.             {
  290.             }
  291.         else if (MenuItem == mCloseFile)
  292.             {
  293.                 DisassemblyWindowClose(Window);
  294.             }
  295.         else if (MenuItem == mCopy)
  296.             {
  297.                 TextEditDoMenuCopy(Window->Editor);
  298.             }
  299.         else if (MenuItem == mSelectAll)
  300.             {
  301.                 TextEditDoMenuSelectAll(Window->Editor);
  302.             }
  303.         else if (MenuItem == mFind)
  304.             {
  305.                 switch (DoFindDialog(&GlobalSearchString,&GlobalReplaceString,
  306.                     mCut,mPaste,mCopy,mUndo,mSelectAll,mClear))
  307.                     {
  308.                         default:
  309.                             EXECUTE(PRERR(ForceAbort,
  310.                                 "DisassemblyWindowDoMenuCommand:  bad value from DoFindDialog"));
  311.                             break;
  312.                         case eFindCancel:
  313.                         case eDontFind:
  314.                             break;
  315.                         case eFindFromStart:
  316.                             SetTextEditInsertionPoint(Window->Editor,0,0);
  317.                             TextEditFindAgain(Window->Editor,GlobalSearchString);
  318.                             TextEditShowSelection(Window->Editor);
  319.                             break;
  320.                         case eFindAgain:
  321.                             TextEditFindAgain(Window->Editor,GlobalSearchString);
  322.                             TextEditShowSelection(Window->Editor);
  323.                             break;
  324.                     }
  325.             }
  326.         else if (MenuItem == mFindAgain)
  327.             {
  328.                 TextEditFindAgain(Window->Editor,GlobalSearchString);
  329.                 TextEditShowSelection(Window->Editor);
  330.             }
  331.         else if (MenuItem == mShowSelection)
  332.             {
  333.                 TextEditShowSelection(Window->Editor);
  334.             }
  335.         else if (MenuItem == mEnterSelection)
  336.             {
  337.                 char*                        NewString;
  338.  
  339.                 NewString = TextEditGetSelection(Window->Editor);
  340.                 if (NewString != NIL)
  341.                     {
  342.                         ReleasePtr(GlobalSearchString);
  343.                         GlobalSearchString = NewString;
  344.                     }
  345.             }
  346.         else
  347.             {
  348.                 EXECUTE(PRERR(AllowResume,
  349.                     "DisassemblyWindowDoMenuCommand:  unknown menu command"));
  350.             }
  351.     }
  352.